package ProR;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

import ProR.Login;




public class Main extends Frame{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	/**
	 * @param args
	 */
	private JLabel labelMain,labelSub;
	private JButton buttonProducts,buttonEmployee,buttonOrder;
	Product product = new Product();
	Employee employee = new Employee();
	Order order = new Order();
	Login l;
	public Main(){
	
		//set Property Fram
		setTitle("Music Shop");
		setBackground(new Color(238, 238, 238));
		setLayout(null);
		//set Font
		Font txtFont = new Font("Tahoma",Font.PLAIN,12); 
		//setComponent
		JPanel panel = new JPanel(null);
			
		labelMain = new JLabel();	labelMain.setFont(new Font("Segoe UI",Font.BOLD,18));
		labelMain.setIcon(new ImageIcon("D:\\Project\\src\\pic\\Logo.png"));
		
		labelSub = new JLabel("Main Menu..");	labelSub.setFont(new Font("Tahoma",Font.BOLD,12));
		labelSub.setIcon(new ImageIcon("D:\\Project\\src\\pic\\menu.png"));
		
		buttonProducts = new JButton("PRODUCTS");	buttonProducts.setFont(txtFont);
		buttonProducts.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		buttonProducts.setIcon(new ImageIcon("D:\\Project\\src\\pic\\Product.png"));
		
		buttonEmployee = new JButton("EMPLOYEE");	buttonEmployee.setFont(txtFont);
		buttonEmployee.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		buttonEmployee.setIcon(new ImageIcon("D:\\Project\\src\\pic\\Employee.png"));
		
		buttonOrder = new JButton("ORDERS");	buttonOrder.setFont(txtFont);
		buttonOrder.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		buttonOrder.setIcon(new ImageIcon("D:\\Project\\src\\pic\\Order.png"));
		
		//add component on panel
		panel.add(labelMain);
		panel.add(labelSub);
		panel.add(buttonProducts);
		panel.add(buttonEmployee);
		panel.add(buttonOrder);
		
		//add panel class to Main windows
		add(product);
		add(employee);
		add(order);   
		
		if(Login.getPrivilege() == 1){
			buttonEmployee.setVisible(false);
		}
		else
			buttonEmployee.setVisible(true);
		
		
		product.setVisible(true);
		employee.setVisible(false);
		order.setVisible(false);
		
		labelMain.setBounds(210, 10, 190, 80);
		labelSub.setBounds(10, 10, 150, 20);
		buttonProducts.setBounds(10, 98, 115, 30);
		buttonEmployee.setBounds(240, 98, 115, 30);
		buttonOrder.setBounds(460, 98, 115, 30);
		setBounds(390, 90, 589, 614);
		panel.setBounds(5, 20, 575, 150);
		panel.setVisible(true);
		add(panel);
		
		buttonProducts.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				employee.setVisible(false);
				order.setVisible(false);
				product.setVisible(true);
			}
		});
		
		buttonEmployee.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				product.setVisible(false);
				order.setVisible(false);
				employee.setVisible(true);
			}
		});
		
		buttonOrder.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				product.setVisible(false);
				employee.setVisible(false);
				order.setVisible(true);
			}
		});
		setResizable(false);
		setVisible(true);
		
		this.addWindowListener(new WindowAdapter() {
			
			@Override
			public void windowClosing(WindowEvent arg0) {
				// TODO Auto-generated method stub
				int confirm = JOptionPane.showConfirmDialog(null, "ต้องการที่จะออกจากโปรแกรมหรือไม่?","Confirm",JOptionPane.OK_CANCEL_OPTION);
				if(confirm == 0){
					dispose();
					new Login().setVisible(true);
				}
				}//end confirm
		});//end window listener
	}
}

